package com.yang.springcloud.service;

import com.yang.springcloud.pojo.Student;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class StudentClientServiceFallbackFactory implements FallbackFactory {

    //降级
    @Override
    public StudentClientService create(Throwable throwable) {
        return new StudentClientService(){

            @Override
            public Map<String, Object> addStudent(Student s) {
                Map<String, Object> msg = new HashMap<String, Object>();
                msg.put("massage", "客户端提供了降级信息，服务暂时关闭");
                msg.put("code", 500);
                return msg;
            }

            @Override
            public Map<String, Object> delereStudent(String name) {
                Map<String, Object> msg = new HashMap<String, Object>();
                msg.put("massage", "客户端提供了降级信息，服务暂时关闭");
                msg.put("code", 500);
                return msg;
            }

            @Override
            public Map<String, Object> updateStudent(Student s) {
                Map<String, Object> msg = new HashMap<String, Object>();
                msg.put("massage", "客户端提供了降级信息，服务暂时关闭");
                msg.put("code", 500);
                return msg;
            }

            @Override
            public List<Student> queryAll() {
                List<Student> studentList = new ArrayList<>();
                Student s = new Student("120", "客户降级","0000-00-00", "Sorry");
                studentList.add(s);
                return studentList;
            }

            @Override
            public Student queryById(String passid) {
                Student s = new Student("120", "客户降级","0000-00-00", "Sorry");
                return s;
            }

        };
    }
}
